package com.module.my.set.view

import android.content.Intent
import android.net.Uri
import android.text.TextUtils
import com.module.app.arouter.ArouterUtils
import com.module.app.base.BaseFragment
import com.module.app.base.BaseViewModel
import com.module.app.bean.ConfigBean
import com.module.app.pop.ListPop
import com.module.app.bean.ListData
import com.module.base.utils.CommonUtils
import com.module.base.utils.ToastUtils
import com.module.my.R
import com.module.my.databinding.MyFragSetContactBinding
import com.module.my.utils.startProblem
import com.module.third.bean.IThirdType
import com.module.third.qq.QQUtils
import com.module.third.wx.WxUtils
import java.util.*

/**
 * Author: yanxuwen
 * Date: 2023/3/17
 * Desc: 联系我们
 */
class SetContactFragment : BaseFragment<BaseViewModel, MyFragSetContactBinding>() {

    override fun bingViewModel() {
        mDatabind.vm = mViewModel
        mDatabind.click = this
    }

    override fun onLazyLoad() {
    }

    fun onClickNotice() {
        var msgService = com.module.app.arouter.ArouterUtils.getMsgService();
        msgService?.startHotMsgActivity(context)
    }

    fun onClickProblem() {
        context.startProblem()
    }

    fun onClickContact() {
        val list: MutableList<com.module.app.bean.ListData> = ArrayList()
        list.add(com.module.app.bean.ListData(1, "微信", true))
        list.add(com.module.app.bean.ListData(2, "QQ", true))
        if (!TextUtils.isEmpty(com.module.app.bean.ConfigBean.getInstance().qqGroupKey)) {
            list.add(com.module.app.bean.ListData(3, "QQ群", true))
        }
        val qq = "1218968265"
        val wx = "19906058322"
        ListPop.show(context, list, object : ListPop.Listener {
            override fun onClick(listData: com.module.app.bean.ListData) {
                if (listData.type == 1) {
                    CommonUtils.copyToClipBoard(context, wx)
                    ToastUtils.showShort(R.string.copy_suc)
                    context?.let {
                        WxUtils(it, lifecycle).jumpWx(it)
                    }

                } else if (listData.type == 2) {
                    QQUtils(lifecycle).jumpQQFriend(context, qq)
                } else if (listData.type == 3) {
                    QQUtils(lifecycle).jumpQQGroup(
                        context,
                        com.module.app.bean.ConfigBean.getInstance().getQqGroupKey()
                    )
                }
            }
        })
    }

    fun onClickFeedback() {
        var msgService = com.module.app.arouter.ArouterUtils.getMsgService();
        msgService?.startAddMsgActivity(context)
    }

    fun onClickEvaluate() {
        try {
            val uri = Uri.parse("market://details?id=" + context?.packageName)
            val intent = Intent(Intent.ACTION_VIEW, uri)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(intent)
            ToastUtils.showShort("记得给好评哦~")
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    fun onClickShare() {
        val list: MutableList<com.module.app.bean.ListData> = ArrayList()
        list.add(com.module.app.bean.ListData(1, "微信", true))
        list.add(com.module.app.bean.ListData(2, "朋友圈", true))
        ListPop.show(context, list, object : ListPop.Listener {
            override fun onClick(listData: com.module.app.bean.ListData) {
                context?.let {
                    if (listData.type == 1) {
                        WxUtils(it, lifecycle).shareUrl(
                            IThirdType.IShareType.TYPE_WX,
                            com.module.app.bean.ConfigBean.getInstance().qrCode,
                            CommonUtils.getString(R.string.app_name),
                            "加密相册、加密视频",
                            R.mipmap.app_icon_logo
                        )
                    } else if (listData.type == 2) {
                        WxUtils(it, lifecycle).shareUrl(
                            IThirdType.IShareType.TYPE_FRIENDS,
                            com.module.app.bean.ConfigBean.getInstance().qrCode,
                            CommonUtils.getString(R.string.app_name),
                            "加密相册、加密视频",
                            R.mipmap.app_icon_logo
                        )
                    }
                }

            }
        })
    }

}